package com.yy.chapter6.validation;

import org.hibernate.validator.internal.metadata.raw.ConstrainedElement;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author yangyao
 * @Description: TODO
 * @date 2018/10/23 10:19
 */
public class MyValidImpl implements ConstraintValidator<MyValid,Object> {

    private String values;

    @Override
    public void initialize(MyValid myValid) {
            this.values = myValid.values();
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        String[] idx_value = values.split(",");
        Boolean flag = false;
        for (int i = 0; i < idx_value.length; i++) {
            if (idx_value[i].equals(o)){
                flag = true;
                break;
            }
        }
        return flag;
    }
}
